package com.share.controller;

import com.share.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * created by caifan 2018/06/04
 */
@RestController
@RequestMapping("/rest/order")
public class OrderController {
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    LoadBalancerClient loadBalancerClient;

    @GetMapping("/user/{id}")
    public User findById(@PathVariable("id")Long id) {
        return restTemplate.getForObject("http://microservice-provider-user:7012/rest/user/" + id, User.class);
    }

    @GetMapping("/getIPAndPort")
    public String getIPAndPort() {
        return restTemplate.getForObject("http://microservice-provider-user/rest/user/getIPAndPort", String.class);
    }

}
